package com.jintoufs.service.bill.impl;

import com.jintoufs.dao.QueryFilters;
import com.jintoufs.dao.bill.BillInfoMapper;
import com.jintoufs.domain.bill.BillInfo;
import com.jintoufs.service.bill.BillService;
import org.cosmos.modules.exception.ServiceException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by yangpeng on 2018/2/27.
 */
@Service("billService")
public class BillServiceImpl implements BillService{
    @Resource
    BillInfoMapper billInfoMapper;

    @Override
    public BillInfo saveBillInfo(BillInfo billInfo) {
        billInfoMapper.insertSelective(billInfo);
        return billInfo;
    }

    @Override
    public List<Map<String, Object>> getByFilter(QueryFilters filters) {
        return billInfoMapper.getByFilter(filters);
    }

    @Override
    public void auth(String id,String type) throws ServiceException {
        BillInfo billInfo = billInfoMapper.selectByPrimaryKey(id);
        if(billInfo == null){
            throw new ServiceException("未找到对应的开票记录，请检查");
        }
//        if("0".equals(billInfo.getStatus()) || "2".equals(billInfo.getStatus())){
//            billInfo.setStatus("1");
//        }else {
//            billInfo.setStatus("2");
//        }
        billInfo.setStatus(type);
        billInfoMapper.updateByPrimaryKeySelective(billInfo);
    }
}
